package ch02Sort;


//选择排序
public class Selection extends Sort
{
    //每次循环把a[i]当做最小元素，遍历i+1~n找出最小元素与a[i]交换
    public static void sort(Comparable[] a) {
        int n = a.length;
        for (int i = 0; i < n-1; i++) {
            int min_idx = i;
            for (int j = i + 1; j < n; j++) {
                if (less(a[j],a[min_idx])){
                    min_idx = j;
                }
            }
            exch(a,i,min_idx);
        }

    }
    public static void main(String[] args) {

        sort(Sort.a);
        System.out.print("现数组：");
        show(Sort.a);
        System.out.print("isSorted？");
        System.out.println(isSorted(Sort.a));
    }


}
